package parse;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aos.util.UploadFileOne;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import com.creawor.hz_market.t_advertisement.UploadFileForm;
import com.creawor.hz_market.t_basestation.t_basestation_importHandle;
import com.creawor.hz_market.t_village_signal.t_village_signal_importHandle;
import com.creawor.imei.base.BaseAction;
import com.creawor.imei.util.UUIDGenerator;

public class UploadFileAction extends BaseAction {
	
	
	public String doAdd(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
			throws Exception {
			UploadFileForm vo = (UploadFileForm)form;
			FormFile file = vo.getFile();
			String yeah=request.getParameter("year");
			String month=request.getParameter("month");
			String day=request.getParameter("day");
			
			String date=yeah+"-"+month+"-"+day;
			if(file!=null)
			{
			    String rootFilePath = getServlet().getServletContext().getRealPath("/");
			    rootFilePath = (new StringBuilder(String.valueOf(rootFilePath))).append(UploadFileOne.strPath).toString();
			    String strAppend = (new StringBuilder(String.valueOf(UUIDGenerator.nextHex()))).append(UploadFileOne.getFileType(file)).toString();
			    if(file.getFileSize() != 0)
			    {
			        String strReturn = UploadFileOne.fileUploadOne(file, rootFilePath, strAppend);
			        request.setAttribute("imageUploadErrors", strReturn);
			        if(strReturn != null)
			        {
			            System.out.println((new StringBuilder("\u7167\u7247\u4E0A\u4F20\u5931\u8D25\uFF1A\uFF1A")).append(strReturn).toString());
			        } else
			        {
			            System.out.println((new StringBuilder("\u91CD\u547D\u540D\u524D\u7684\u6587\u4EF6\u540D\u4E3A\uFF1A\uFF1A")).append(file.getFileName()).append("\u6587\u4EF6\u5927\u5C0F\u4E3A\uFF1A\uFF1A").append(file.getFileSize()).toString());
			            System.out.println((new StringBuilder("\u6587\u4EF6\u5B8C\u6574\u7684\u8DEF\u5F84\u4E3A\uFF1A")).append(rootFilePath).append(strAppend).toString());
//			            vo.setFile((new StringBuilder(String.valueOf(UploadFileOne.strPath))).append(strAppend).toString());
			            
			            String xmltype = vo.getDoctype();
						if ("1".equals(xmltype)) {
							BalanceHandle ex=new BalanceHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ex.readExcel(file.getInputStream());
							ex.insertInfo();
						}
						if ("2".equals(xmltype)) {
							CountyHandle ex = new CountyHandle();
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);
						}
						if ("3".equals(xmltype)) {
							CustomerHandle ex = new CustomerHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);
						}
						if ("4".equals(xmltype)) {
							ADHandle ex = new ADHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);
						}
						if ("5".equals(xmltype)) {
							HallHandle ex = new HallHandle();
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ex.readExcel(file.getInputStream());
							ex.insertInfo();
						}
						if ("6".equals(xmltype)) {
							ChannelHandle ex=new ChannelHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ex.readExcel(file.getInputStream());
							ex.insertInfo();
						}
						if ("7".equals(xmltype)) {
							GroupHandle ex = new GroupHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);
						}
						if ("8".equals(xmltype)) {
							t_village_signal_importHandle ex = new t_village_signal_importHandle();
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);
						}
						if ("9".equals(xmltype)) {
							t_basestation_importHandle ex = new t_basestation_importHandle();
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);
						}
						if ("10".equals(xmltype)) {
							UserHandle ex = new UserHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);
						}
			        }
			    }
			}
			request.setAttribute("operating-status", "!!!!!!!!!");
			System.out.println("in the end....");
			return "aftersave";
		}
	
}
